package com.dyness.sdsp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dyness.sdsp.domain.SdspCity;
import com.dyness.sdsp.domain.SysMessage;
import com.dyness.sdsp.service.SdspCityService;
import com.dyness.sdsp.mapper.SdspCityMapper;
import com.dyness.sdsp.service.SysMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @author gaohaiqing
* @description 针对表【sdsp_city】的数据库操作Service实现
* @createDate 2024-01-05 14:50:29
*/
@Service
@Slf4j
public class SdspCityServiceImpl extends ServiceImpl<SdspCityMapper, SdspCity>
    implements SdspCityService{

    @Autowired
    private SysMessageService sysMessageService;

    @Override
    @Transactional
    public void saveData(List<SysMessage> sysMessageList, List<SdspCity> sdspCityList) {
        log.info("\n\n====================保存数据====================\n\n");
        sysMessageList.forEach(message -> {
            LambdaQueryWrapper<SysMessage> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(SysMessage::getCode, message.getCode());
            wrapper.eq(SysMessage::getLanguage, message.getLanguage());
            sysMessageService.remove(wrapper);
            sysMessageService.save(message);
        });

        // LambdaQueryWrapper<SdspCity> wrapper = new LambdaQueryWrapper<>();
        // wrapper.eq(SdspCity::getCode, city.getCode());
        // remove(wrapper);
        sdspCityList.forEach(this::save);
        log.info("\n\n=====================保存数据完成==================\n\n");
    }

    @Override
    public void truncateTable() {
        super.remove(new LambdaQueryWrapper<SdspCity>());
    }
}




